package br.edu.ifrn.atamtracer.controle;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.edu.ifrn.atamtracer.session.FachadaUsuarioRemote;

public class ServiceLocator {
	private static InitialContext jndi = null;
	
	public static FachadaUsuarioRemote getFachadaUsuarioRemote() {
		FachadaUsuarioRemote fachadaUsuario = null;
		try {
			getInitialContext();
			fachadaUsuario = (FachadaUsuarioRemote) jndi.lookup("ATAMTracerApp/FachadaUsuario/remote");
		} catch (NamingException e) {
			e.printStackTrace();
		}
		return fachadaUsuario;
	}
	
	public static void getInitialContext() throws NamingException {
		if (jndi == null) {
			Properties env = new Properties();
			env.put(Context.SECURITY_PRINCIPAL, "guest" );
			env.put(Context.SECURITY_CREDENTIALS, "guest" );
			env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
			env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
			jndi = new InitialContext(env);
		} 
	}
}
